package qj.app.p1;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import qj.tool.build.BuildUtil;
import qj.util.NetUtil;
import qj.util.SocketUtil;
import qj.util.funct.P1;

public class PortForwarder {
	public static void main(String[] args) {
		int localPort = 8080;
		final String remoteHost = "172.18.4.37";
		final int reportPort = 8080;
		forwardPort(localPort, remoteHost, reportPort);
	}
	
//	public static class Build {
//		public static void main(String[] args) {
//			BuildUtil.buildApp(PortForwarder.class);
//		}
//	}

	public static void forwardPort(int localPort, final String remoteHost,
			final int reportPort) {
		NetUtil.acceptF(localPort, new P1<Socket>() {public void e(Socket sk) {
			try {
				SocketUtil.connect(sk, new Socket(remoteHost,reportPort));
			} catch (UnknownHostException e1) {
				throw new RuntimeException(e1);
			} catch (IOException e1) {
				throw new RuntimeException(e1);
			}
		}}).e();
	}
}
